package hong;

import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.media.AudioClip;
import javafx.stage.Screen;

import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Constants {

    public static int SCREEN_WIDTH = 1300;
    public static int SCREEN_HEIGHT = 720;
    public static AudioClip audio;
    public static URL timeDesktopFXML;
    public static URL timeDownLayoutFXML;
    public static Map<String,Image> images = new HashMap<>();

    public static void initData(){
//        获取屏幕宽高
        //javafx
        Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
        SCREEN_WIDTH = (int) visualBounds.getWidth();
        SCREEN_HEIGHT = (int) (visualBounds.getHeight()- 30);
        //awt 不推荐，会报错  Error:(3,21) java: 程序包 com.sun.glass.ui 不可见
//        List<?> screens = Toolkit.getToolkit().getScreens();
//        Screen screen = (Screen) screens.get(0);
//        SCREEN_WIDTH = screen.getVisibleWidth();
//        SCREEN_HEIGHT = screen.getVisibleHeight() - 30;
        //加载资源文件
        ClassLoader classLoader = Constants.class.getClassLoader();
        timeDesktopFXML = classLoader.getResource("timeDesktop.fxml");
        timeDownLayoutFXML = classLoader.getResource("timeDownLayout.fxml");
        String urlRes = timeDesktopFXML.toString();
        urlRes = urlRes.substring(0,urlRes.lastIndexOf(File.separator));
        audio = new AudioClip(urlRes + "/audio/fengLing.mp3");
        images.put("img_run",new Image(urlRes + "/image/run.png"));
        images.put("img_stop",new Image(urlRes + "/image/stop.png"));
//        audioPath = classLoader.getResource("audio/dingDong_daZhong.wav");//获取不到了，jdk8可以
//        audio = new AudioClip(audioPath.toString());
//        String userDir = System.getProperty("user.dir");//获取out文件夹所在路径或.exe,.jar所在文件夹的路径
//        audio = new AudioClip("file://" + userDir + "/target/classes/audio/dingDong_daZhong.wav");
//        audio = new AudioClip("file://" + userDir + "/target/classes/audio/fengLing.mp3");
//        Media media = new Media("file:/D:/sound.wav");
//        MediaPlayer mediaPlayer = new MediaPlayer(media);
//        mediaPlayer.play();
//        images.put("img_run",new Image(classLoader.getResourceAsStream("image/run.png")));
    }
}
